package com.enjoyor.soa.traffic.core.tpcms.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.tpcms.domain.InfoStopRoad;
import com.enjoyor.soa.traffic.core.tpcms.mapper.IInfoStopRoadMapper;
import com.enjoyor.soa.traffic.core.tpcms.service.IStopRoadService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;

@Service
@Transactional
@SuppressWarnings("rawtypes")
public class StopRoadService implements IStopRoadService {

    @Autowired
    private IInfoStopRoadMapper stopRoadMapper;

    @Autowired
    private IPubLogMapper pubLogMapper;

    @Value("${log.system.name}")
    private String systemName;

    @Override
    public Page getStopRoadPage(Page page) {
        return stopRoadMapper.selectPageInfo(page);
    }

    @Override
    public List<InfoStopRoad> getStopRoadList(Map<String, Object> map) {
        return stopRoadMapper.selectListInfo(map);
    }

    /**
     * 添加线路
     */
    @Override
    public void insertStopRoad(InfoStopRoad infoStopRoad, String userName) {
        infoStopRoad.setStopRoadId("R" + TimeHelper.getUniqueString());
        infoStopRoad.setUpdateTime(TimeHelper.dateToLongString());
        infoStopRoad.setIsDelete("0");
        stopRoadMapper.insert(infoStopRoad);
        pubLogMapper.saveNoramlLogInfo(userName, systemName, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
                String.format("添加InfoStopRoad表单编号:{%s} 操作成功!", new Object[] { infoStopRoad.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.PROHIBITION_LINE_MANAGEMENT.getMessage());
    }

    /**
     * 修改线路信息
     */
    @Override
    public void editStopRoad(InfoStopRoad infoStopRoad, String userName) {
        infoStopRoad.setIsDelete("0");
        infoStopRoad.setUpdateTime(TimeHelper.dateToLongString());
        stopRoadMapper.updateById(infoStopRoad);
        pubLogMapper.saveNoramlLogInfo(userName, systemName, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
                String.format("修改InfoStopRoad表单编号:{%s} 操作成功!", new Object[] { infoStopRoad.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.PROHIBITION_LINE_MANAGEMENT.getMessage());
    }

    /**
     * 删除线路
     */
    @Override
    public void deleteStopRoad(String stopRoadId, String userName) {
        InfoStopRoad infoStopRoad = new InfoStopRoad();
        infoStopRoad.setStopRoadId(stopRoadId);
        infoStopRoad.setIsDelete("1");
        infoStopRoad.setUpdateTime(TimeHelper.dateToLongString());
        stopRoadMapper.updateByIdSelective(infoStopRoad);
        pubLogMapper.saveNoramlLogInfo(userName, systemName, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_DELETE.getCode(),
                String.format("删除InfoStopRoad表单编号:{%s} 操作成功!", new Object[] { infoStopRoad.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.PROHIBITION_LINE_MANAGEMENT.getMessage());
    }

    /**
     * 绘制地图区域信息
     */
    @Override
    public void drawingRoadShape(InfoStopRoad infoStopRoad, String userName) {
        infoStopRoad.setUpdateTime(TimeHelper.dateToLongString());
        stopRoadMapper.drawingRoadShape(infoStopRoad);
        pubLogMapper.saveNoramlLogInfo(userName, systemName, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
                String.format("绘制区域地理信息编号:{%s} 操作成功!", new Object[] { infoStopRoad.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.PROHIBITION_LINE_MANAGEMENT.getMessage());
    }

}
